package com.app.miwawa.api.portal.service.bo;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.framework.common.api.entity.CommonEntityAware;
import org.framework.common.api.query.Criterion.Operator;
import org.framework.common.api.query.Criterion.ValueType;
import org.framework.common.api.service.dao.CommonDaoAware;
import org.framework.common.api.support.model.QueryModel;
import org.framework.common.ext.util.DateUtil;
import org.framework.common.ext.util.DateUtil.DateRange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.app.miwawa.api.portal.service.dao.DashboardDao;
import com.app.miwawa.api.system.entity.view.Account;

/**
 * 业务接口
 * <p>
 * 描述: 工作台账
 * </p>
 * <p>
 * Company: Professional
 * </p>
 * 
 * @author chanlong(陈龙)
 * @date 2016年2月12日 下午10:55:29
 * @version 1.0.2016
 */
@Service("dashboardBo")
public class DashboardBo {

	@Autowired
	private DashboardDao dao;
	
	@Resource(name = "defaultDao")
	private CommonDaoAware<CommonEntityAware<String>, String> defaultDao;

	public Map<String, Object> adviser(Account account) throws Exception {
		Map<String, Object> result = new LinkedHashMap<String, Object>();
		
		List<Map<String, Object>> salescount = dao.pro_salescount(account);
		List<Map<String, Object>> salesranking = dao.pro_salesranking();
		
		QueryModel model = new QueryModel();
		model.setLimit(0);
		model.setOffset(0);
		model.setEntityClass("com.app.miwawa.api.esm.entity.view.CustomerView");
		
		model.clearAndQuery();
		model.addAndQuery("isparent", "true", Operator.EQ);
		model.addAndQuery("status", "promise", Operator.EQ);
		model.addAndQuery("invalid", "F", Operator.EQ);
		model.addAndQuery("bespokeType", "看店", Operator.EQ);
		model.addAndQuery("promiseDate", DateUtil.range(DateRange.MONTH, new Date()),Operator.BETWEEN, ValueType.DATES);
		model.addOrder("bespokeDate", true);
		List<?> bespokecustomer = defaultDao.findByQuery(model).getRows();
		
		result.put("salescount", salescount);
		result.put("salesranking", salesranking);
		result.put("bespokecustomer", bespokecustomer);
		
		return result;
	}

	public Map<String, Object> teacher(Account account, Map<String, String> map) throws Exception {
		Map<String, Object> result = new LinkedHashMap<String, Object>();
		
		List<Map<String, Object>> schedule = dao.pro_schedule(account);
		List<Map<String, Object>> checkrate = dao.pro_checkrate(account);
		List<Map<String, Object>> calloncount = dao.pro_calloncount(account);
		
		result.put("schedule", schedule);
		result.put("checkrate", checkrate);
		result.put("calloncount", calloncount);
		
		return result;
	}

	public Map<String, Object> leaders(Account account) throws Exception {
		Map<String, Object> result = new LinkedHashMap<String, Object>();
		
		List<Map<String, Object>> consuming = dao.sql_consuming();
		
		List<Map<String, Object>> yearofsales = dao.pro_yearofsales();
		
		result.put("consuming", consuming);
		result.put("yearofsales", yearofsales);
		
		return result;
	}
}
